<template>
	<view class="main">		
	  <!-- #ifdef MP-WEIXIN -->
	  <navbar  title="订单支付" :isGoBack="true" :isNotice="true" :bgColor="bgColor" :btnColors='btnColor' :visible="true" ></navbar>
	  <!-- #endif -->	
	 
		
	<u-popup :show="show" mode="bottom"  @close="close" @open="open" :round="10">
		<view class="flex cancel-button">
			<u-icon name="close-circle" color="#999999" size="22" @click="close()"></u-icon>					
		</view>  
		<view class="main-cur flex flex-direction align-center text-center text-dff ">
			
			<view class="flex flex-direction justify-center pl-20 pr-20 pt-10 align-center">		
				<view class="flex align-center text-center">
					<text style="font-size: 40rpx;color: #222222;margin-top: 10rpx;line-height: 22px;">￥</text>
					<text class="flex" style="font-weight: bold;font-size: 72rpx;color: #222222;line-height: 32px;" >{{goods_total}}</text>	
				</view>
				<view class="flex align-center text-center mt-10">
					<text class="ml-20  mr-15" style="font-size: 28rpx;color: #888888">剩余时间</text>	
					<u-count-down :time="30 * 60 * 60 * 1000" format="HH:mm:ss"></u-count-down>
				</view>
				
			</view>			
			<view class="flex justify-between align-center text-center" style="margin-top: 40rpx;font-size: 32rpx;color: #222222;width: 652rpx;">				
				<text class="ml-15">订单信息</text>
				<text class="ml-15">{{pay_no}}</text>
			</view>	
			
			<view class="flex justify-between align-center text-center" style="margin-top: 40rpx;font-size: 32rpx;color: #222222;margin-bottom: 100rpx;width: 652rpx;">
				<text class="ml-15">付款方式</text>
				<text class="ml-15">微信</text>
			</view>	
			
		</view>
	    <view class="flex flex-direction ml-20 mr-20">	  
			<view class="submit-btn-leftt mt-30"  @click="handleClickHome()">立即支付</view>      				    				
	    </view>	
	</u-popup>		
	</view>
</template>

<script>
	export default {
		
		data() {
		   	return {
				...getApp().globalData.config,
				orderInfo:{},
				pay_no:'WX794670782766811687376',
				type:2,
				show:true,
				goods_total:'0.00',
				userInfo:{},
				payInfo:{}
			}			
		},
		onShow() {			
			this.userInfo=uni.getStorageSync('userInfo');
			this.order_pay()
				
		},
		onLoad(options) {
			this.pay_no=options.pay_no
			this.goods_total=options.goods_total
			if(options.type){
				this.type=options.type
			}
		},
		onBackPress(e) {
		    this.$routers.router('/pages/order/index','navigateTo') 
		},
		
		
		methods:{
			getUsers(){
				let that=this;
				let obj_data={
					token:uni.getStorageSync('userInfo').token
				};
				this.$http.getUser(obj_data).then(res=>{				
					if(res.resCode=='9999'){
						uni.setStorageSync('userInfo',res.data);	
					    that.userInfo=res.data
					}				
				})
			},
			close(){
				this.show=false
				this.$routers.router('/pages/order/index','switchTab')  
			},
			handleClickOrder(){
				 this.$routers.router('/pages/order/index','navigateTo')  
			},
			
			handleClickHome(){
				let parms={
					money:this.goods_total,
					pay_no:this.pay_no,
					PayeeInfo:this.payInfo.PayeeInfo
				}			
				
				let rest = this.payInfo
				 uni.requestPayment({
				 	provider: 'wxpay',
				 	timeStamp: rest.data.timeStamp,
				 	nonceStr: rest.data.nonceStr,
				 	package: rest.data.package,
				 	signType:rest.data.signType,
				 	paySign: rest.data.paySign,
				 	success: function (res) {
				 		uni.navigateTo({
							url:"/pages/pagesOrder/success/index?parms="+JSON.stringify(parms)
						})
				 	},
				 	fail: function (err) {
				 		uni.switchTab({
				 			url:"/pages/order/index"
				 		})
				 	},									
				 });			
			},
			order_pay(){
				let wx_openid=this.userInfo.wx_openid
				let that=this;
				if(!wx_openid){
					uni.login({
						success: function(loginRes) {
							let obj_data={
								pay_no:that.pay_no,
								type:that.type,
								token:uni.getStorageSync('userInfo').token,
								code:loginRes.code
							}
							console.log('obj_data',obj_data)
							that.$http.order_info(obj_data).then(res=>{
								  if(res.resCode=='9999'){
									  that.payInfo=res.data
								  }
								
							})
						},
						fail: function(error) {
							// 登录失败的回调
							console.error('登录失败：', error);
						}
					});
					
				}else{
					let obj_data={
						pay_no:this.pay_no,
						type:this.type,
						token:uni.getStorageSync('userInfo').token,
					}
					this.$http.order_info(obj_data).then(res=>{
						  if(res.resCode=='9999'){
							  this.payInfo=res.data
						  }
						
					})
				}
				
			}
		}
	}
</script>

<style>
		@import "./index.css";
</style>